package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type MaterialThemeTerminals struct {
	ID            string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	ThemeID       string `json:"theme_id" gorm:"column:theme_id;type:int;size:64;index:terminal,unique,priority:1;comment:身份id"`
	RobotID       string `json:"robot_id" gorm:"column:robot_id;type:string;size:40;index:terminal,unique,priority:2;comment:设备id"`
	TerminalType  string `json:"terminal_type" gorm:"column:terminal_type;type:string;size:64;index:terminal,unique,priority:3;not null;default:'';comment:终端类型"`
	UpgradeStatus int    `json:"upgrade_status" gorm:"column:upgrade_status;type:int;size:8;comment:升级状态"`
	UpgradeType   int    `json:"upgrade_type" gorm:"column:upgrade_type;type:int;size:8;comment:类型,1新增,2编辑,3删除"`
	CreatedAt     int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt     int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

func (MaterialThemeTerminals) TableName() string {
	return "material_theme_terminals_v2"
}

// BeforeCreate 自增id
func (u *MaterialThemeTerminals) BeforeCreate(tx *gorm.DB) (err error) {
	if u.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	u.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MaterialThemeTerminals{})
}
